import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;

public class Identificator {
	private final Robot r;
	
	public Identificator(Robot robot) {
		r = robot;
	}
	
	public boolean[][] identifie(int iniX, int iniY, int width, int height) {
//		final int xCorner = 648;
//		final int yCorner = 900 - 597;
//		final int delta = 30;
        final int xCorner = MoveGesture.xTopLeftCorner + 34;
        final int yCorner = MoveGesture.yTopLeftCorner + 181;
        final int delta = MoveGesture.delta;
        
        try {
			Thread.sleep(Main.refreshRate * 2);
		} catch (InterruptedException e) {}
		BufferedImage img = r.createScreenCapture(
				new Rectangle(
						xCorner + iniX * delta,
						yCorner + iniY * delta,
						width * delta,
						height * delta
						)
				);
		boolean[][] res = new boolean[height][width];
		for (int i = 0; i < width; i++) {
			for (int j = 0; j < height; j++) {
				res[j][i] = isColored(img.getRGB(i * delta, j * delta));
			}
		}
		return res;
	}
	
	public static boolean isColored(int pixel) {
		int red = (pixel >> 16) & 0xff;
		int green = (pixel >> 8) & 0xff;
		int blue = pixel & 0xff;
		return red > 200 || green > 200 || blue > 230;
	}
}
